package com.lavegue.webaction;

import java.util.List;

import com.lavegue.common.Constants;
import com.lavegue.common.ListAction;
import com.lavegue.model.BisGroup;
import com.lavegue.model.BisType;
import com.lavegue.model.Company;
import com.lavegue.service.BisGroupService;
import com.lavegue.service.BisTypeService;
import com.lavegue.service.CompanyService;

/**
 * author: tinazhifen
 * description:
 *
 */
public class BisGroupAction extends ListAction<BisGroup> {
	//模板分组Service
	private BisGroupService bisGroupService; 
	private BisTypeService bisTypeService;
	private CompanyService companyService;
	private int disGroupId;
	
	private List<BisType> listType;
	private List<Company> listCompany;
	
	//更新的值
	private String updateName="";//更新的分组名称
	private int companyId;
	private int listTypeId;
	private int upId;
	private int pageId;
	
    //新增的值
	private String addName;
	private int addTypeId;
	private int addcompanyId;

	//查询需要的值
	private int serTypeId=0;//查看时选择的分类
	private String groupName="";//分组名称

	//管理模块分组，根据分组名称列出所以的模块分组
	public String allBisGroupListByName()
	{
		 if(null==this.getSessionAtrribute(Constants.MAN_SESSION_USER))
		   {
			   return "lg";
		   }
		pageObj=bisGroupService.getAllBisGroupByNameAndTypeId(pageNo, pageSize,null,0);
		listType=bisTypeService.findAll();
		listCompany=companyService.findAll();
		return "listBisGroup";
	}
	
	//删除模块分组
	public String delBisGroup()
	{
	    BisGroup bisGroup=bisGroupService.findById(disGroupId);
	    if(bisGroup!=null){
	    	bisGroupService.deleteById(disGroupId);
	    }
		return allBisGroupListByName();
	}

    //更新分组	
	public String updateBisGroup()
	{
		
		BisGroup upBisGroup=bisGroupService.findById(upId);
		  upBisGroup.setBisType(bisTypeService.findById(listTypeId));
		  if(companyId!=0){
		  upBisGroup.setCompany(companyService.findById(companyId));
		  }else
		  {
			  upBisGroup.setCompany(null);
		  }
		upBisGroup.setName(updateName);
		bisGroupService.update(upBisGroup);
		pageNo=pageId;
		return allBisGroupListByName();
	}
	
	//新增加分组
	public String addBisGroup()
	{
		BisGroup addBisGroup=new BisGroup();
		addBisGroup.setBisType(bisTypeService.findById(addTypeId));
		 if(addcompanyId!=0){
			 addBisGroup.setCompany(companyService.findById(addcompanyId));
		  }else
		  {
			  addBisGroup.setCompany(null);
		  }
		 addBisGroup.setName(addName);
		bisGroupService.save(addBisGroup);
		return allBisGroupListByName();
	}
	
	
	//根据分类和分组名称查询
	
	public String serachBisGroup()
	{
		pageObj=bisGroupService.getAllBisGroupByNameAndTypeId(pageNo, pageSize,groupName,serTypeId);
		listType=bisTypeService.findAll();
		listCompany=companyService.findAll();
		return "listBisGroup";
	}
	
	
	
	
	public BisGroupService getBisGroupService() {
		return bisGroupService;
	}

	public void setBisGroupService(BisGroupService bisGroupService) {
		this.bisGroupService = bisGroupService;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public BisTypeService getBisTypeService() {
		return bisTypeService;
	}


	public void setBisTypeService(BisTypeService bisTypeService) {
		this.bisTypeService = bisTypeService;
	}


	public CompanyService getCompanyService() {
		return companyService;
	}


	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}


	public List<BisType> getListType() {
		return listType;
	}


	public void setListType(List<BisType> listType) {
		this.listType = listType;
	}


	public List<Company> getListCompany() {
		return listCompany;
	}


	public void setListCompany(List<Company> listCompany) {
		this.listCompany = listCompany;
	}


	public int getDisGroupId() {
		return disGroupId;
	}

	public void setDisGroupId(int disGroupId) {
		this.disGroupId = disGroupId;
	}


	public String getUpdateName() {
		return updateName;
	}


	public void setUpdateName(String updateName) {
		this.updateName = updateName;
	}


	public int getCompanyId() {
		return companyId;
	}


	public void setCompanyId(int companyId) {
		this.companyId = companyId;
	}


	public int getListTypeId() {
		return listTypeId;
	}


	public void setListTypeId(int listTypeId) {
		this.listTypeId = listTypeId;
	}


	public int getPageId() {
		return pageId;
	}


	public void setPageId(int pageId) {
		this.pageId = pageId;
	}


	public int getUpId() {
		return upId;
	}


	public void setUpId(int upId) {
		this.upId = upId;
	}


	public String getAddName() {
		return addName;
	}


	public void setAddName(String addName) {
		this.addName = addName;
	}


	public int getAddTypeId() {
		return addTypeId;
	}


	public void setAddTypeId(int addTypeId) {
		this.addTypeId = addTypeId;
	}


	public int getAddcompanyId() {
		return addcompanyId;
	}


	public void setAddcompanyId(int addcompanyId) {
		this.addcompanyId = addcompanyId;
	}


	public int getSerTypeId() {
		return serTypeId;
	}


	public void setSerTypeId(int serTypeId) {
		this.serTypeId = serTypeId;
	}
	
	
	
}

